
package com.windgo.config;

import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;

/**
 * @author 张林浩
 * @since 2022/10/11 23:08
 */
public class MarketSessionManager extends DefaultWebSessionManager {

    private static final String MARKET_ADMIN_HEADER = "X-CskaoyanMarket-Admin-Token";
    private static final String MARKET_WX_HEADER = "X-CskaoyanMarket-Token";

    @Override
    protected Serializable getSessionId(ServletRequest servletRequest, ServletResponse response) {
        HttpServletRequest request = (HttpServletRequest) servletRequest;

        String sessionId = request.getHeader(MARKET_ADMIN_HEADER);
        if (sessionId != null && !"".equals(sessionId)) {
            return sessionId;
        }
        String sessionId1 = request.getHeader(MARKET_WX_HEADER);
        if (sessionId1 != null && !"".equals(sessionId1)) {
            return sessionId1;
        }
        return super.getSessionId(servletRequest, response);
    }
}
